package com.bite.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Slf4j
@Aspect
//@Component
public class AspectDemo {

    @Pointcut("execution(* com.bite.aop.controller.*.*(..))")
    public void pt(){}

    @Before("pt()")
    public void doBefore(){
        log.info("AspectDemo 执行doBefore...");
    }

    @After("pt()")
    public void doAfter(){
        log.info("AspectDemo 执行doAfter...");
    }

    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("AspectDemo 执行doAfterReturning...");
    }
    @AfterThrowing("pt()")
    public void doAfterThrowing(){
        log.info("AspectDemo 执行doAfterThrowing...");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint jt){
        log.info("around 前处理");
        Object proceed = null;
        try {
            proceed = jt.proceed();
        } catch (Throwable e) {
            log.error("around 发生异常...");
        }
        log.info("around 后处理");
        return proceed;
    }
}
